package dsl.rulesengine

class RulesEngine {

    def rulesLogic
    def rulesEngineDelegate


    RulesEngine(rulesLogic) {
        this.rulesLogic = rulesLogic
        rulesEngineDelegate = new RulesEngineDelegator(rulesLogic)
    }

    def execute(String scriptFile, Map bindings) {

        Binding binding = new Binding(bindings)
        def shell = new GroovyShell(binding)

        def script = shell.parse(new File(scriptFile))

        script.metaClass = new RulesEngineMetaClass(script.class, rulesEngineDelegate)
        script.run()
    }

}